# -*- coding: utf-8 -*-
import serial,time,json,redis
rd = redis.Redis(host='127.0.0.1',port=6379)
conffile = open('config.json','r')

confstr = conffile.read()
conf = json.loads(confstr)

def getTemp(ser):
    temp = 0
    if ser!=None:
        ser.write("?T\r\n".encode())
        tmp = ser.readline().decode()
        if tmp.find('T') >0:
            temp = float(tmp[2:])
    return temp
	
	
ser2 = serial.Serial(conf["TempSerialPort"], 9600, timeout=0.5)

while(1):
	tmp = getTemp(ser2)
	rd.set("temperature",tmp,10)
	time.sleep(1)
